package pokeronlab_2014.mcts;

import java.util.Random;

import com.biotools.meerkat.Deck;

public class CardNode extends TreeNode{

	/**
	 * A kártyák amiket kiosztunk a gyerekeknek
	 */
	Deck cardsForChildren;
	
	public CardNode(TreeNode node) {
		super(node);
		//annyi gyereke van, ahány kártya maradt...
		numberOfChildren = state.deck.cardsLeft();
		cardsForChildren = new Deck();
		cardsForChildren.copy(state.deck);
	}

	@Override
	public TreeNode select() {
		return children[new Random().nextInt(numberOfChildren)];
	}

	@Override
	public TreeNode simulate() {
		TreeNode ret = new NodeFactory().getNode(this);
		return ret;
	}

	@Override
	//nem kell index szerint lekérni gyereket, szal mindegy hogy mit kapnak
	public void expand() {
		children = new TreeNode[numberOfChildren];
		for (int i = 0; i < numberOfChildren; i++) {
			children[i] = new NodeFactory().getNode(this);
			children[i].state.dealCard(
					cardsForChildren.extractRandomCard().getIndex());
		}
	}

}
